package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.AddCountDeposit;
import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.service.business.AddCountDepositService;
import com.tbit.uqbike.service.rpcservice.PurviewService;
import com.tbit.uqbike.webmanager.dao.core.AddCountDepositDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenmengran
 * @Description: 押金
 * @date 2019\12\27 002710:44
 */
@Service
public class AddCountDepositServiceImpl implements AddCountDepositService {
    @Autowired
    private PurviewService purviewService;
    @Autowired
    private AddCountDepositDao addCountDepositDao;

    @Override
    public void add(LoginInfo loginInfo, AddCountDeposit addCountDeposit) {
        if (!purviewService.purviewCheck(loginInfo.id, addCountDeposit.getAccountId())) {
            throw new BaseException(SystemCodeEnum.NO_PRIVILEGE);
        }

        addCountDepositDao.insert(addCountDeposit);
    }

    @Override
    public AddCountDeposit getByAccountId(LoginInfo loginInfo, Integer accountId) {
        if (!purviewService.purviewCheck(loginInfo.id, accountId)) {
            throw new BaseException(SystemCodeEnum.NO_PRIVILEGE);
        }

        return addCountDepositDao.getByAccountId(accountId);
    }

    @Override
    public AddCountDeposit getByAccountId(Integer accountId) {
        return addCountDepositDao.getByAccountId(accountId);
    }
}
